<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    exit(0);
}

require_once '../config/database.php';
require_once '../includes/Response.php';

// 获取请求路径
$request_uri = $_SERVER['REQUEST_URI'];
$path = parse_url($request_uri, PHP_URL_PATH);
$path = str_replace('/api/', '', $path);
//写入日志
file_put_contents('log.txt', $request_uri . "\n", FILE_APPEND);
// 路由处理
switch ($path) {
    case 'sync':
        require_once 'sync.php';
        break;
    case 'register':
        require_once 'register.php';
        break;
    case 'login':
        require_once 'login.php';
        break;
    default:
        Response::error('API endpoint not found', 404);
}
?> 